package vn.edu.saigontech.ncms.web.bookstore.report;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import vn.edu.saigontech.ncms.model.bookstore.Item;
import vn.edu.saigontech.ncms.model.system.Parameter;
import vn.edu.saigontech.ncms.service.ItemService;
import vn.edu.saigontech.ncms.service.ParameterService;
import vn.edu.saigontech.ncms.util.DateUtil;
import vn.edu.saigontech.ncms.util.I18n;

public class ImportExportReport {
	private String fromDate;
	private String toDate;
	private List<ImportExportDetail> bookReportDetails;
	private List<ImportExportDetail> cdReportDetails;
	private String lep;
	private String acc;
	private String bsr;
	
	public ImportExportReport(Date fromDate, Date toDate) {
		this.fromDate = DateUtil.toString(fromDate, new I18n().getMessage("format.vndate"));
		this.toDate = DateUtil.toString(toDate, new I18n().getMessage("format.vndate"));
		this.bookReportDetails = new ArrayList<ImportExportDetail>();
		this.cdReportDetails = new ArrayList<ImportExportDetail>();
		this.init(fromDate, toDate);
	}

	private void init(Date fromDate, Date toDate) {
		Collection<Item> items = ItemService.INSTANCE.findAll();
		for(Item item : items) {
			if(item.isBook()) {
				this.bookReportDetails.add(new ImportExportDetail(item, fromDate, toDate));
			} else if(item.isCD()) {
				this.cdReportDetails.add(new ImportExportDetail(item, fromDate, toDate));
			}
		}
		this.lep = ParameterService.INSTANCE.findText(Parameter.LEP);
		this.acc = ParameterService.INSTANCE.findText(Parameter.ACC);
		this.bsr = ParameterService.INSTANCE.findText(Parameter.BSR);
	}
	
	public String getLep() {
		return lep;
	}

	public void setLep(String lep) {
		this.lep = lep;
	}

	public String getAcc() {
		return acc;
	}

	public void setAcc(String acc) {
		this.acc = acc;
	}

	public String getBsr() {
		return bsr;
	}

	public void setBsr(String bsr) {
		this.bsr = bsr;
	}

	public String getFromDate() {
		return fromDate;
	}

	public void setFromDate(String fromDate) {
		this.fromDate = fromDate;
	}

	public String getToDate() {
		return toDate;
	}

	public void setToDate(String toDate) {
		this.toDate = toDate;
	}

	public List<ImportExportDetail> getBookReportDetails() {
		return bookReportDetails;
	}

	public void setBookReportDetails(List<ImportExportDetail> bookReportDetails) {
		this.bookReportDetails = bookReportDetails;
	}

	public List<ImportExportDetail> getCdReportDetails() {
		return cdReportDetails;
	}

	public void setCdReportDetails(List<ImportExportDetail> cdReportDetails) {
		this.cdReportDetails = cdReportDetails;
	}
}
